<template>
	<view class="my-page">
		<u-navbar leftIconColor="#ffffff" :autoBack="true" :placeholder="true" bgColor="rgba(255,255,255,0.0)">
			<view slot="center" class="nav-title">
				实名认证
			</view>
		</u-navbar>
		<view class="content">
			<view class="title">
				实名认证
			</view>
			<view class="text">
				请填写真实姓名和身份证号
			</view>
			<!-- <view class="item" v-if="info.real_name_status == 0||info.real_name_status == 3">
				<view class="item-left">
					<view class="item-title">
						头面像
					</view>
					<view class="item-text">
						上传您的身份证头面像
					</view>
				</view>
				<image src="../../../static/home/real-head.png" v-if="zimg == ''" @click="changeAvatar(1)" mode=""></image>
				<image :src="zimg" v-else mode=""></image>
			</view>
			<view class="item" v-if="info.real_name_status == 0||info.real_name_status == 3">
				<view class="item-left">
					<view class="item-title">
						国徽面
					</view>
					<view class="item-text">
						上传您的身份证国徽面
					</view>
				</view>
				<image src="../../../static/home/real-behind.png"  v-if="fimg == ''" @click="changeAvatar(2)" mode=""></image>
				<image :src="fimg" v-else mode=""></image>
			</view> -->
			<view class="item" v-if="info.real_name_status == 0||info.real_name_status == 3">
				<u--input color="#ffffff" placeholder="请输入姓名" border="none" v-model="name"></u--input>
			</view>
			<view class="item" v-if="info.real_name_status == 0||info.real_name_status == 3">
				<u--input color="#ffffff" placeholder="请输入本人身份证号" border="none" v-model="identity"></u--input>
			</view>
			<view class="item" v-if="info.real_name_status == 0||info.real_name_status == 3">
				<u--input color="#ffffff" placeholder="请输入紧急联系人号码" border="none" v-model="tell"></u--input>
			</view>
			<view class="btn" v-if="info.real_name_status == 0">
				<u-button style="color: #000;"  size="large" color="linear-gradient(255.89deg, #FFF0E3 6.94%, #D7B39A 87.16%)" shape="circle" @click="gobuy"
					type="primary" text="提交"></u-button>
			</view>
			<view class="btn" v-if="info.real_name_status == 1">
				<u-button style="color: #000;"  size="large" color="linear-gradient(255.89deg, #FFF0E3 6.94%, #D7B39A 87.16%)" shape="circle" type="primary"
					text="已实名"></u-button>
			</view>
			<view class="btn" v-if="info.real_name_status == 2">
				<u-button style="color: #000;"  size="large" color="linear-gradient(255.89deg, #FFF0E3 6.94%, #D7B39A 87.16%)" shape="circle" type="primary"
					text="审核中"></u-button>
			</view>
		<!-- 	<view class="btn" v-if="info.real_name_status == 3">
				<u-button @click="gobuy" color="#090B08" shape="circle" type="primary"
					text="重新提交"></u-button>
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				identity: '',
				tell: '',
				info: {},
				zimg:'',
				fimg:''
			}
		},
		onLoad() {
			this.postuserinfo()
		},
		methods: {
			changeAvatar(e) {
				let app = this
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'],
					crop: {
						quality: 60, // 高质量保存(90%)
						resize: false // 不强制调整到精确像素
					},
					success: (res) => {
						app.avatarTempPath = res.tempFilePaths[0]
						app.uploadAvatar(e)
					}
				})
			},
			uploadAvatar(e) {
				let app = this
				uni.showLoading({
					title: '上传中...'
				})
				// 这里需要替换为你的上传接口
				uni.uploadFile({
					url: 'https://api.eachidc.com/api/upload/upload',
					filePath: app.avatarTempPath,
					name: 'file',
					header: {
						'tokenSJZX': uni.getStorageSync("token")
					},
					success: (uploadRes) => {
						const res = JSON.parse(uploadRes.data)
						if (res.code == 1) {
							if(e == 1){
								app.zimg = res.url
							}else{
								app.fimg = res.url
							}
						} else {
							uni.$u.toast(res.msg || '上传失败')
						}
					},
					fail: () => {
						uni.$u.toast('上传失败')
					},
					complete: () => {
						uni.hideLoading()
					}
				})
			},
			postuserinfo() {
				this.$Request({
					method: 'POST',
					url: '/api/personal/myIndex',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data.user
					}
				})

			},
			gobuy() {
				// if (this.zimg == '') {
				// 	uni.showToast({
				// 		title: '请上传身份证头像面！',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				// if (this.fimg == '') {
				// 	uni.showToast({
				// 		title: '请上传身份证国徽面！',
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				if (this.name == '') {
					uni.showToast({
						title: '请输入姓名！',
						icon: 'none'
					})
					return
				}
				if (this.identity == '') {
					uni.showToast({
						title: '请输入身份证号码！',
						icon: 'none'
					})
					return
				}
				if (this.tell == '') {
					uni.showToast({
						title: '请输入手机号！',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					mask: true
				})
				let params = {
					name: this.name,
					id_card: this.identity,
					mobile: this.tell,
					cardimg1:this.zimg,
					cardimg2:this.fimg
				}
				this.$Request({
					method: 'POST',
					url: '/api/personal/realNamePost',
					data: params,
					ismsg: true,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.postuserinfo()
					}
				})
			},
		}
	}
</script>
<style>
	page{
		background: #000000;
	}
</style>
<style lang="scss" scoped>
	.my-page {
		height: 100vh;
		position: relative;
		background-image: url('../../../static/login/login-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 593px;
		padding: 30rpx;

		.nav-title {
			color: #ffffff;
		}

		.content {
			margin-top: 60rpx;
			padding: 30rpx;

			.title {
				font-size: 42rpx;
				color: #ffffff;
				font-weight: bold;
				text-align: center;
			}

			.text {
				color: #999999;
				font-size: 26rpx;
				margin-top: 20rpx;
				text-align: center;
			}

			.item {
				padding: 30rpx;
				background-color: #1A1A1B;
				margin-top: 30rpx;
				border-radius: 30rpx;
				display: flex;
				justify-content: space-between;

				.item-left {
					.item-title {
						color: #000;
						font-size: 32rpx;
						font-weight: bold;
					}

					.item-text {
						color: #999999;
						font-size: 28rpx;
					}
				}
			}

			.btn {
				margin-top: 60rpx;
			}
		}
	}
</style>